<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Java开发入门与数据类型 | 浪飞IT小栈</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="前后端技术分享">
    <meta name="keywords" content="前端博客,后端博客,人工智能,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown,java,Spring,Springboot,Redis,mysql">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.ada71c49.css" as="style"><link rel="preload" href="/assets/js/app.a2a00aa5.js" as="script"><link rel="preload" href="/assets/js/2.256f807a.js" as="script"><link rel="preload" href="/assets/js/13.0a6ebfcf.js" as="script"><link rel="prefetch" href="/assets/js/10.ab144fe3.js"><link rel="prefetch" href="/assets/js/11.062e0879.js"><link rel="prefetch" href="/assets/js/12.f9c60882.js"><link rel="prefetch" href="/assets/js/14.03fc6f12.js"><link rel="prefetch" href="/assets/js/15.19dbf9fd.js"><link rel="prefetch" href="/assets/js/16.6e68160b.js"><link rel="prefetch" href="/assets/js/17.1d678834.js"><link rel="prefetch" href="/assets/js/18.4536fd5c.js"><link rel="prefetch" href="/assets/js/19.9c1b65df.js"><link rel="prefetch" href="/assets/js/20.c5f96e71.js"><link rel="prefetch" href="/assets/js/21.3f0b334e.js"><link rel="prefetch" href="/assets/js/22.55c868be.js"><link rel="prefetch" href="/assets/js/23.91286241.js"><link rel="prefetch" href="/assets/js/24.c1af1909.js"><link rel="prefetch" href="/assets/js/25.a995a755.js"><link rel="prefetch" href="/assets/js/26.abc5dea3.js"><link rel="prefetch" href="/assets/js/27.1eb62850.js"><link rel="prefetch" href="/assets/js/28.b383a871.js"><link rel="prefetch" href="/assets/js/29.088e0d73.js"><link rel="prefetch" href="/assets/js/3.cd716564.js"><link rel="prefetch" href="/assets/js/30.3ccc98d5.js"><link rel="prefetch" href="/assets/js/31.aab7cc23.js"><link rel="prefetch" href="/assets/js/32.5e16b7e6.js"><link rel="prefetch" href="/assets/js/33.4aaeb741.js"><link rel="prefetch" href="/assets/js/34.45e8e898.js"><link rel="prefetch" href="/assets/js/35.5899c97a.js"><link rel="prefetch" href="/assets/js/36.32e2e263.js"><link rel="prefetch" href="/assets/js/37.c4e27bbd.js"><link rel="prefetch" href="/assets/js/38.fe5e60d2.js"><link rel="prefetch" href="/assets/js/39.2cb0b4ee.js"><link rel="prefetch" href="/assets/js/4.edf4d5e7.js"><link rel="prefetch" href="/assets/js/40.08d5bead.js"><link rel="prefetch" href="/assets/js/41.2f80f24b.js"><link rel="prefetch" href="/assets/js/42.43a49913.js"><link rel="prefetch" href="/assets/js/43.08da7ec2.js"><link rel="prefetch" href="/assets/js/44.7c7cb8a9.js"><link rel="prefetch" href="/assets/js/45.0ddf7e7f.js"><link rel="prefetch" href="/assets/js/46.7c4609a5.js"><link rel="prefetch" href="/assets/js/47.edf3ddf8.js"><link rel="prefetch" href="/assets/js/48.569a90b9.js"><link rel="prefetch" href="/assets/js/49.fa368ac8.js"><link rel="prefetch" href="/assets/js/5.24054156.js"><link rel="prefetch" href="/assets/js/50.b9b3ea7f.js"><link rel="prefetch" href="/assets/js/51.a2ebf0fe.js"><link rel="prefetch" href="/assets/js/52.31f02238.js"><link rel="prefetch" href="/assets/js/53.4110ef1e.js"><link rel="prefetch" href="/assets/js/54.dab741c7.js"><link rel="prefetch" href="/assets/js/55.f27984e9.js"><link rel="prefetch" href="/assets/js/56.bd4c1a8e.js"><link rel="prefetch" href="/assets/js/57.375d40cb.js"><link rel="prefetch" href="/assets/js/58.932e3864.js"><link rel="prefetch" href="/assets/js/59.e657be1b.js"><link rel="prefetch" href="/assets/js/6.b259c061.js"><link rel="prefetch" href="/assets/js/60.88d94274.js"><link rel="prefetch" href="/assets/js/61.fa71d884.js"><link rel="prefetch" href="/assets/js/62.a9d3b3b7.js"><link rel="prefetch" href="/assets/js/63.f849fe75.js"><link rel="prefetch" href="/assets/js/64.1770f7a9.js"><link rel="prefetch" href="/assets/js/65.6afc33db.js"><link rel="prefetch" href="/assets/js/66.799f2eb4.js"><link rel="prefetch" href="/assets/js/67.f36b2f7d.js"><link rel="prefetch" href="/assets/js/68.868cd00b.js"><link rel="prefetch" href="/assets/js/69.4c29b907.js"><link rel="prefetch" href="/assets/js/7.e34ea00f.js"><link rel="prefetch" href="/assets/js/70.1b993ed4.js"><link rel="prefetch" href="/assets/js/71.e16ad4f9.js"><link rel="prefetch" href="/assets/js/72.627505e6.js"><link rel="prefetch" href="/assets/js/73.32768e14.js"><link rel="prefetch" href="/assets/js/74.968a580d.js"><link rel="prefetch" href="/assets/js/75.42d5af3d.js"><link rel="prefetch" href="/assets/js/76.19a69d31.js"><link rel="prefetch" href="/assets/js/77.cf627a78.js"><link rel="prefetch" href="/assets/js/78.07177880.js"><link rel="prefetch" href="/assets/js/8.c4dd00ce.js"><link rel="prefetch" href="/assets/js/9.0ff73be2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.ada71c49.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="浪飞IT小栈" class="logo"> <span class="site-name can-hide">浪飞IT小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/avatar.jpg"> <div class="blogger-info"><h3>浪飞yes</h3> <span>无法简单的人儿~</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>开篇</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>基础语法</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/a5bdcf/" class="sidebar-link">计算机导论与环境配置</a></li><li><a href="/pages/32e9a2/" aria-current="page" class="active sidebar-link">Java开发入门与数据类型</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/32e9a2/#一、今日学习内容和目标" class="sidebar-link">一、今日学习内容和目标</a></li><li class="sidebar-sub-header level2"><a href="/pages/32e9a2/#二、java和跨平台" class="sidebar-link">二、Java和跨平台</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_2-1-术语概述" class="sidebar-link">2.1 术语概述</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_2-1-1-计算机语言" class="sidebar-link">2.1.1 计算机语言</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_2-1-2-什么是编程" class="sidebar-link">2.1.2 什么是编程</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_2-1-3-java语言" class="sidebar-link">2.1.3 Java语言</a></li><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_2-2-跨平台原理" class="sidebar-link">2.2 跨平台原理</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_2-2-1-平台相关性" class="sidebar-link">2.2.1 平台相关性</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_2-2-2-跨平台性" class="sidebar-link">2.2.2 跨平台性</a></li><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_2-3-java开发和环境搭建" class="sidebar-link">2.3 Java开发和环境搭建</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/32e9a2/#三、第一个java程序" class="sidebar-link">三、第一个Java程序</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_3-1-helloworld" class="sidebar-link">3.1 HelloWorld</a></li><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_3-2-java编译和运行机制" class="sidebar-link">3.2 Java编译和运行机制</a></li><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_3-3-常见问题" class="sidebar-link">3.3 常见问题</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/32e9a2/#四、java基本语法" class="sidebar-link">四、Java基本语法</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_4-1-基本语法" class="sidebar-link">4.1 基本语法</a></li><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_4-2-注释符号" class="sidebar-link">4.2 注释符号</a></li><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_4-3-关键字、分隔符和标识符" class="sidebar-link">4.3 关键字、分隔符和标识符</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_4-3-1-关键字" class="sidebar-link">4.3.1 关键字</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_4-3-1-语言分隔符" class="sidebar-link">4.3.1 语言分隔符</a></li><li class="sidebar-sub-header level4"><a href="/pages/32e9a2/#_4-4-2-标识符" class="sidebar-link">4.4.2 标识符</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/32e9a2/#五、数据类型与常量" class="sidebar-link">五、数据类型与常量</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_5-1-常量" class="sidebar-link">5.1 常量</a></li><li class="sidebar-sub-header level3"><a href="/pages/32e9a2/#_5-2-数据类型" class="sidebar-link">5.2 数据类型</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/32e9a2/#六、小结与作业" class="sidebar-link">六、小结与作业</a></li></ul></li><li><a href="/pages/0ccc48/" class="sidebar-link">变量和运算符</a></li><li><a href="/pages/67fd43/" class="sidebar-link">选择语句和循环语句</a></li><li><a href="/pages/92a804/" class="sidebar-link">一维数组</a></li><li><a href="/pages/0840c0/" class="sidebar-link">方法定义与使用</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>面向对象</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>常用类</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础高级</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>数据库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端技术</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>热门框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前后端分离</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>权限控制</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>NoSQL</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>微服务</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>消息中间件</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>脚手架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>技术增值</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=Java%E9%80%9F%E9%80%9A" title="分类" data-v-06225672>Java速通</a></li><li data-v-06225672><a href="/categories/?category=%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95" title="分类" data-v-06225672>基础语法</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/langfeiyes" target="_blank" title="作者" class="beLink" data-v-06225672>langfeiyes</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2024-02-28</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">Java开发入门与数据类型<!----></h1>  <div class="theme-vdoing-content content__default"><h1 id="java开发入门与数据类型"><a href="#java开发入门与数据类型" class="header-anchor">#</a> Java开发入门与数据类型</h1> <h2 id="一、今日学习内容和目标"><a href="#一、今日学习内容和目标" class="header-anchor">#</a> 一、今日学习内容和目标</h2> <ul><li>Java语言和跨平台原理
<ul><li>了解什么是计算机语言</li> <li>理解什么是java的跨平台原理</li></ul></li> <li>掌握如何搭建开发和运行环境</li> <li>必须掌握HelloWorld程序的开发
<ul><li>HelloWorld程序编写、编译、运行</li> <li>使用IDEA工具来开发HelloWorld程序</li></ul></li> <li>必须记住Java的基本语法
<ul><li>必须记住基本语法</li> <li>了解注释符号有哪些</li> <li>了解什么是关键字</li> <li>了解java的分隔符和标志符有哪些，记住标识符命名规则</li></ul></li> <li>掌握数据类型和常量
<ul><li>必须掌握八大基本数据类型的常量写法</li></ul></li></ul> <h2 id="二、java和跨平台"><a href="#二、java和跨平台" class="header-anchor">#</a> 二、Java和跨平台</h2> <h3 id="_2-1-术语概述"><a href="#_2-1-术语概述" class="header-anchor">#</a> <strong>2.1</strong> 术语概述</h3> <h4 id="_2-1-1-计算机语言"><a href="#_2-1-1-计算机语言" class="header-anchor">#</a> 2.1.1 计算机语言</h4> <p>​		在生活中的两个人需要交流，无非是采用一种彼此都能够识别的语言。那么，我们说该语言是他们传递信息的媒介。那么什么是计算机语言呢？计算机语言是指用于人与计算机之间通讯的一种特殊语言，是人与计算机之间传递信息的媒介。</p> <p>​		为什么需要和计算机交流呢？计算机怎么能读懂我们给它发出的信息？和计算机交流的目的，就是让计算机帮我们完成复杂工作，比如大量数据的运算。为了让计算机能读懂我们发出的信息，此时就需要编写一套由字符、数字所组成并按照某种语法格式的一串串计算机指令，而这些指令和命令就是计算机语言。</p> <p>​		<strong>所以，通过计算机语言，人类可以命令计算机帮我们完成复杂的工作。</strong></p> <h4 id="_2-1-2-什么是编程"><a href="#_2-1-2-什么是编程" class="header-anchor">#</a> 2.1.2 什么是编程</h4> <p>​		我们已经知道，使用计算机语言告诉计算机，并让计算机帮我们完成一些人做起来比较复杂的工作。</p> <p>​		那计算机怎么知道我们要它解决的问题是什么，怎么知道解决问题的具体的步骤是什么呢？此时我们就得通过计算机语言去告诉计算机：<strong>需要做什么</strong>，<strong>怎么一步一步去做</strong>。这种人和计算机之间交流的过程，我们称之为<strong>编程</strong>。</p> <h4 id="_2-1-3-java语言"><a href="#_2-1-3-java语言" class="header-anchor">#</a> 2.1.3 Java语言</h4> <p>​			Java语言是美国Sun公司，在1995年推出的高级的编程语言。所谓编程语言，是计算机的语言，人们可以使用编程语言对计算机下达命令，让计算机完成人们需要的功能。2009年，Sun公司被甲骨文公司收购，所以我们现在访问oracle官网即可：https://www.oracle.com</p> <p>Java语言共同创始人之一：詹姆斯·高斯林 （James Gosling），被称为“Java之父”，以下是Java语言的Logo</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/rL5xZNjy7UbYqlf.png" alt=""></em></p> <p>Java的三大平台：JavaSE、JavaEE，JavaME （<strong>知道即可</strong>）</p> <ul><li>Java SE：Java标准平台，它允许开发软件运行在个人电脑桌面上(用户需要下载，安装)，我们即将使用的IDEA开发工具就属于桌面端应用。 <strong>JavaSE适合做桌面端应用程序</strong> ，同时JavaSE也是JavaEE的基础。</li></ul> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/Zfa5NT2w4MDBSUG.png" alt=""></strong></p> <ul><li>Java EE：Java企业平台，它允许开发的软件运行在服务器上，针对<strong>Web方向</strong>，主要应用于开发企业项目和互联网项目，如淘宝，京东，12306，各大银行网站等。<strong>JavaEE 适合做服务器端程序开发</strong></li></ul> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/QwXCHOMIU4hAabn.png" alt=""></em></p> <ul><li>Java ME （了解）：Java微型平台，用来开发早期嵌入式移动设备上的软件，比如早期功能机上的Java游戏。</li></ul> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/XjSiVIUtkKw2xMA.png" alt=""></em></p> <p>思考题：</p> <p>小米/华为等Android系统中的程序使用Java语言的哪个版本开发的？</p> <h3 id="_2-2-跨平台原理"><a href="#_2-2-跨平台原理" class="header-anchor">#</a> 2.2 跨平台原理</h3> <h4 id="_2-2-1-平台相关性"><a href="#_2-2-1-平台相关性" class="header-anchor">#</a> 2.2.1 平台相关性</h4> <p>Windows系统只能运行Windows的程序（exe），Linux系统只能运行Linux的程序，Mac系统只能运行Mac的程序。</p> <p>Windows的可执行文件，不能直接运行在Linux系统中，反之亦然，就好比Android手机不能运行iPhone的App程序一样，我们把这种情况称之为平台相关性。</p> <h4 id="_2-2-2-跨平台性"><a href="#_2-2-2-跨平台性" class="header-anchor">#</a> 2.2.2 跨平台性</h4> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/4QXsuqDexcf3Ppz.png" alt=""></em></p> <p><strong>一份（源）代码，多次编译，到处运行</strong></p> <p>​		使用特定平台的编译器所编译的程序只能在对应的平台运行，此时会发现编译器是与平台相关的，编译后的文件也是与平台相关的。</p> <p>​		我们说的<strong>语言跨平台是编译后的文件跨平台</strong>。</p> <p>​		那语言的跨平台性如何实现？拿Java举例，我们可以对Java程序进行编译操作，编译后生成一种和平台系统无关的文件——字节码文件。但是此时Windows、Linux是不能直接执字节码文件的，只有Java虚拟机（JVM）才能执行字节码文件，那么为了在Windows系统上运行该Java程序，我们就只能在Windows平台上安装Windows版本的JVM，如果要在Mac系统上运行，那么得安装Mac版本的JVM。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/tVyf1kKluTWwrFI.png" alt=""></em></p> <p>那么如此一来，Java就实现了跨平台，也就达到了**“一次编译，到处运行”**的效果。</p> <p><strong>Java之所以能跨平台有两个原因：</strong></p> <ul><li><p>Java文件经过编译后生成和平台无关的class文件</p></li> <li><p>Java虚拟机（JVM）是不跨平台的</p></li></ul> <p>在这里进行编译操作的工具叫做javac，启动JVM并把字节码加载进JVM的工具叫做java。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/DHR2yULMIKOhNrF.png" alt=""></p> <p>这里解释几个术语：</p> <ul><li><p>源代码：简称源码，是指还未编译的按照编程语言规范书写的代码，比如Java代码</p></li> <li><p>源文件：存放源代码的文件，比如Java文件，拓展名是.java</p></li> <li><p>字节码文件： 经过编译器预处理过的一种文件,是JAVA的可执行文件存在形式，拓展名是.class</p></li></ul> <h3 id="_2-3-java开发和环境搭建"><a href="#_2-3-java开发和环境搭建" class="header-anchor">#</a> 2.3 Java开发和环境搭建</h3> <p><strong>JVM、JRE和JDK概述</strong></p> <ul><li>JVM（Java Virtual Machine）:Java虚拟机，它是运行所有Java程序(Java字节码)的虚拟计算机。JVM是不跨平台的，在Windows下装Windows版的JVM，在Linux下装Linux版的JVM。</li> <li>JRE(Java Runtime Environment)：Java运行环境，如果要运行Java程序，就需要JRE的支持。JRE里包含JVM，还包含运行程序需要的常用类库，一般在只运行程序而不开发程序的服务器中安装。</li> <li>JDK(Java Development Kit)：Java开发工具包，包含开发Java程序的所有工具如javac和java等。JDK包含JRE，如果已经安装了JDK就不必安装JRE。</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code>jvm<span class="token operator">:</span>java虚拟机，专门用于执行java的字节码文件。
jre<span class="token operator">:</span>java程序的运行环境，包含jvm <span class="token operator">+</span> 常用类库
jdk<span class="token operator">:</span>java程序的开发环境， 包含jre <span class="token operator">+</span> javac<span class="token operator">/</span>java等编译运行工具。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="三、第一个java程序"><a href="#三、第一个java程序" class="header-anchor">#</a> 三、第一个Java程序</h2> <p>一般而言，编写的第一个程序，习惯叫做HelloWorld程序。</p> <p>需求：在控制台（Win命令行）界面，打印输出：hello world (你好师姐)</p> <h3 id="_3-1-helloworld"><a href="#_3-1-helloworld" class="header-anchor">#</a> 3.1 HelloWorld</h3> <p>step 1：在开发盘(例如：D盘)创建一个文件夹，命名为day02，此时需要在文件夹选项中启用文件拓展名。在day02下新建文本文档，修改名称为Hello.java。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/7s1IZXFd6YHmN3l.png" alt=""></p> <p>step 2：使用记事本或Editplus或**Notepad++**等文本编辑器，打开Hello.java文件，输入以下代码</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/FXM2aJuszLYZwG4.png" alt="">**</p> <p>step 3：命令行进入当前源文件所在目录。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/Hj6wKX25hCE743g.png" alt="">**</p> <p>step 4：编译&amp;运行</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/U5DTChYBAnsV3Qc.png" alt=""></p> <h3 id="_3-2-java编译和运行机制"><a href="#_3-2-java编译和运行机制" class="header-anchor">#</a> 3.2 Java编译和运行机制</h3> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/20240301195548.png" alt=""></p> <ul><li><p>编写源文件（Java文件），源文件中包含源代码（Java代码）。</p></li> <li><p>使用javac工具对源文件做编译操作，编译过程主要用于进行语法检查。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment">## 编译命令格式</span>
javac 源文件.java   
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div></li> <li><p>生成字节码后，使用java工具启动JVM，运行程序</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment">## 运行字节码的命令格式</span>
<span class="token function">java</span> 拥有主方法的类名
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div></li> <li><p>在控制台输出，显示结果</p></li></ul> <h3 id="_3-3-常见问题"><a href="#_3-3-常见问题" class="header-anchor">#</a> 3.3 常见问题</h3> <p>第一类：大小写问题。Java语言是严格区分大小写的</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/folbyCKMWHESmrN.png" alt=""></p> <p>第二类：中英文输入法问题。所有的代码(除了注释)都要用英文</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/vTVZOCtLBUmIE1q.png" alt=""></p> <h2 id="四、java基本语法"><a href="#四、java基本语法" class="header-anchor">#</a> 四、Java基本语法</h2> <h3 id="_4-1-基本语法"><a href="#_4-1-基本语法" class="header-anchor">#</a> 4.1 基本语法</h3> <ul><li><p><strong>Java程序以类( class ) 组织的，创建Java程序时必须首先得创建一个类。</strong></p></li> <li><p><strong>若一个类必须运行，则必须拥有main方法（主方法）</strong>,因为main方法是程序的入口。</p></li> <li><p><strong>Java语言严格区分大小写</strong>。好比main和Main、system和System是完全不同的概念。</p></li> <li><p>一个Java源文件里可以定义多个Java类，但其中最多只能有一个类被定义成public类。若源文件中包括了public类，源文件必须和该public类同名。</p></li> <li><p>一个源文件中包含N个Java类时，成功编译后会生成N份字节码文件，即每个类都会生成一份单独的class文件，且字节码文件名和其对应的类名相同。</p></li></ul> <h3 id="_4-2-注释符号"><a href="#_4-2-注释符号" class="header-anchor">#</a> 4.2 注释符号</h3> <p>Java的注释信息是给程序员看的，编译器(javac)在编译的时候会忽略掉源文件中的注释信息。</p> <p>Java提供3种注释类型：</p> <pre>单行注释：//	内容, //后面这一行的内容被注释
多行注释：/* 内容  */；/* 和 */ 之间的所有内容被注释
文档注释：/** 内容 */；/** 和 */之间内容被注释，此外，还可以专门生成文档信息API
</pre> <p>**注意：**多行注释之间彼此都不能交叉嵌套，以下就是错误的例子。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/*
  /* 
     注释内容
  */</span>
<span class="token operator">*</span><span class="token operator">/</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><pre>因为 /* 会找距离自己最近的 */ 符号，组成一个注释语句块，上图中单独的*/符号就不能被编译器识别了。
</pre> <p><strong>标准的代码案例（必须这么去做）</strong></p> <p>后续代码的编写，要严格都要 理解需求、<strong>开发步骤</strong>、<strong>小结</strong>，以便初学者<strong>形成编程思维</strong>。</p> <p>需求：在控制台输出内容：你好师姐</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/*
需求：在控制台输出内容：你好师姐
开发步骤：
1：先定义一个类，命名为Hello
2：在Hello类中定义一个main方法
3：在main方法中使用系统输出打印一句话
4：编译和运行程序
*/</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Hello</span> <span class="token punctuation">{</span>
  <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  	<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;你好师姐&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">/*
写完代码后，写下小结：我在写代码过程的得与失
1：如果不写main方法，程序没法运行，因为main方法是程序的入口。  mian
2：Java严格区分大小写，System不能写出system，其他也要注意。
3：巨坑，分号必须使用英文状态下的，不能使用中文(中文的；英文的;)
*/</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h3 id="_4-3-关键字、分隔符和标识符"><a href="#_4-3-关键字、分隔符和标识符" class="header-anchor">#</a> 4.3 关键字、分隔符和标识符</h3> <h4 id="_4-3-1-关键字"><a href="#_4-3-1-关键字" class="header-anchor">#</a> 4.3.1 关键字</h4> <p>关键字：在编程语言中事先定义的，有着特殊含义和用途的单词。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/w3VtZ4Ni5XDyYfR.png" alt=""></em></p> <p>小结：注意关键字和保留字都是由小写组成，关键字不要去记，我们学一个记一个。</p> <h4 id="_4-3-1-语言分隔符"><a href="#_4-3-1-语言分隔符" class="header-anchor">#</a> 4.3.1 语言分隔符</h4> <pre>分号（;）：用于语句的分割，表示一句话结束，好比咱们使用的句号。
花括号（{}）：表示一个代码块，是一个整体，花括号要成对使用。
空格（ ）：把一整条语句分割成几段，空格的次数不限制，好比一句英文里单词都要分开写一样。
方括号（[]）：定义数组和访问数组元素时使用。
圆括号（()）：使用很广泛，具体用到细讲。
圆点（.）：类和对象访问它的成员时使用。
</pre> <p>注意：<strong>必须都是半角状态下的英文符号</strong>，写代码时确保搜狗输入法是这个样子的。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/gNvWdHuSEYJMjly.png" alt=""></em></p> <h4 id="_4-4-2-标识符"><a href="#_4-4-2-标识符" class="header-anchor">#</a> 4.4.2 标识符</h4> <p>在写代码的时候为了增强代码的可阅读性，我们会自定义很多名字。如：类名、方法名、变量名等。</p> <p><strong>在编程的世界里，我们把这种为了增强程序阅读性而自定义的名称，统称为标识符。<strong>标识符的通用命名</strong>规则</strong>（必须记住）</p> <ul><li>由字母、数字、下划线、$组成，但不能以数字开头</li> <li>大小写敏感</li> <li>不得使用java中的关键字</li></ul> <p>不同的标识符有不同的命名规则（后续详细讲）:
类名：类名首字母大写, 其他的字母小写(Hello),如果是多个单词, 后面的单词首字母都大写(HelloWorld)。不用java内置的类名作为自己的类名。
变量名: 未完待续
方法名: 未完待续</p> <h2 id="五、数据类型与常量"><a href="#五、数据类型与常量" class="header-anchor">#</a> 五、数据类型与常量</h2> <h3 id="_5-1-常量"><a href="#_5-1-常量" class="header-anchor">#</a> 5.1 常量</h3> <p>常量（const），程序运行过程中固定不变化的值。</p> <p>如何写常量： 直接在程序中给出的一个值</p> <ul><li><p>字面量:	就表示直接给出的一个值（可以是整数、小数等），也有人称之为直接量。如整数常量1，2，3，小数常量3.14等。</p></li> <li><p>使用final定义的变量（后讲）</p></li></ul> <h3 id="_5-2-数据类型"><a href="#_5-2-数据类型" class="header-anchor">#</a> 5.2 数据类型</h3> <p>生活中，数据都是有类型这个概念的，比如张三18岁，18这个数字就是整型的，买了2.5斤菜，2.5就是小数类型的，在Java中每一个数据也有数据类型。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/3hwAMSQVJix5pBX.png" alt=""></em></p> <p>在计算机中，人为地把8个二进制位称为一个字节(byte)</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token punctuation">(</span>了解<span class="token punctuation">)</span>
<span class="token number">1</span>个二进制位 可以存储<span class="token number">0</span>或<span class="token number">1</span>  		可以存储<span class="token number">2</span>种状态
<span class="token number">2</span>个二进制位 可以存储<span class="token number">00</span>或<span class="token number">01</span> <span class="token number">10</span> <span class="token number">11</span>  可以存储<span class="token number">4</span>种状态
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token number">8</span>个二进制位  可以存储<span class="token number">2</span>的<span class="token number">8</span>次方种状态，<span class="token number">256</span>种状态，如果每个状态我用来存储数字，可以存储<span class="token number">256</span>个数 <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">255</span><span class="token punctuation">]</span><span class="token punctuation">,</span>如果还可以表示负数<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">128</span><span class="token punctuation">,</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>，<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">127</span><span class="token punctuation">]</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">128</span><span class="token punctuation">,</span><span class="token number">127</span><span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>8大基本数据数据类型所<strong>占内存大小</strong> 和可存储的数据范围：</p> <table><thead><tr><th>No.</th> <th>数据类型</th> <th>占位(字节)</th> <th>数据范围</th></tr></thead> <tbody><tr><td>1</td> <td>byte</td> <td>1</td> <td>[ -128 , 127 ]</td></tr> <tr><td>2</td> <td>short</td> <td>2</td> <td>[ -32768 , 32767 ]</td></tr> <tr><td>3</td> <td><strong>int</strong></td> <td><strong>4</strong></td> <td>[ -2^31^ , 2^31^ - 1 ]    ≈  <b>[-21亿，21亿] </b></td></tr> <tr><td>4</td> <td>long</td> <td>8</td> <td>[ -2^63^ , 2^63^-1 ]</td></tr> <tr><td>6</td> <td>float</td> <td>4</td> <td>[-3.4x10^38^ ,   3.4x10^38^]</td></tr> <tr><td>7</td> <td><strong>double</strong></td> <td><strong>8</strong></td> <td>[-1.7x10^308^ ,  1.7x10^308^]</td></tr> <tr><td>5</td> <td>char</td> <td>2</td> <td>[0 ,  2^16^-1]</td></tr> <tr><td>8</td> <td>boolean</td> <td>1个二进制位</td> <td>true,false</td></tr></tbody></table> <pre style="color:red;">提醒：开发者需要明确记住每个具体数据类型所占字节数（内存大小）。
</pre> <p><strong>整数类型常量</strong></p> <p>在 java 中，整型常量默认使用 int 类型来存储 。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">IntTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 控制台输出10，这个10是一个常量，默认使用int存储。</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        
        <span class="token comment">// 控制台输出20，这个20如果想以long类型存储，需要加L</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">20L</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>如果要存储long类型常量，要加L或者l，建议加L。<strong>常用的整数类型是int和long</strong>，byte和short基本不用。</p> <p><strong>小数类型常量</strong></p> <p>小数类型默认是double类型，如果要存储 float 类型常量，要加f或者F。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">DoubleTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 3.14是一个小数常量，默认使用double存储。</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// float类型常量,需要加F/f后缀</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14f</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>另外，实际开发过程中，如何选择这两种数据类型呢？，看小数的位数：</p> <p>float类型精确到6-7位，double精确到15-16位，绝大部分应用程序都采用double类型。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">// float 类型只能精确到6-7</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.141592653f</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// a = 3.1415927</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>注意：</p> <ul><li><strong>小数类型在计算机中存储是不精确的</strong>，所以，float，double 类型的数据不适合用在金融计算领域(不容许舍入误差)。如果需要精确数字计算，需要使用 BigDecimal 类 (后面学) 。</li></ul> <p><strong>字符类型常量</strong></p> <p>Java中的字符表示Unicode（万国码）编码表中的每一个符号，每个符号<strong>使用单引号引起来</strong>，其中前128个符号和ASCII表相同，如下图。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/GaBFbOirpfvWC4t.png" alt=""></em></p> <p>这张表要记住的几个符号，A在码表的顺序是65，a在码表的顺序是97。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CharTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 控制台输出字符A</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token char">'A'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><strong>布尔类型常量</strong></p> <p>boolean 类型只有两个值，true 和 false , 分别表示对与错，在未来的开发中用于逻辑判断。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BooleanTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>字符串类型（String）常量</strong></p> <p>所谓字符串就是多个字符合在一起，使用<strong>双引号</strong>引起来。例如 : 在开发中要打印一个用户的名字就可以使用字符串了，因为一个用户的名字是由多个字符构成的。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">StringDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;叩丁狼&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>提醒：先记住String表示字符串类型就可以了，后续会学习（它属于引用类型先不管）。</p> <p><strong>不同数据类型的常量：</strong></p> <ul><li><p>整数常量，所有整数，如1、2、3、100、200等</p></li> <li><p>小数常量，所有小数，如1.2、2.7、3.14等</p></li> <li><p>字符常量，用单引号括起来的符号如，'A'、'a'、'龙' 等</p></li> <li><p>布尔常量，只有true和false，分别表示对与错</p></li> <li><p>字符串常量，使用双引号括起来的内容如：&quot;Will&quot;、&quot;wolfcode&quot;等</p></li></ul> <p>需求：打印输出每一种数据类型的常量</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TypeDemo</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// int类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// long类型常量,使用L后缀</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">20L</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// float类型常量,使用F后缀</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// double类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// char类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token char">'A'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// boolean类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// String类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;你好&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><p>今日快捷键</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>psvm <span class="token operator">+</span> tab
sout <span class="token operator">+</span> tab
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="六、小结与作业"><a href="#六、小结与作业" class="header-anchor">#</a> 六、小结与作业</h2> <ul><li>了解计算机语言和编程</li> <li>了解Java语言的三个版本 JavaSE/JavaEE/JavaME</li> <li>掌握Java语言跨平台的原理</li> <li>重点掌握java开发和运行环境的搭建</li> <li>重点掌握第一个Java程序的编写、编译、运行**-建议5遍**</li> <li>重点掌握IDEA工具开发第一个Java程序、基本语法**-建议5遍**</li> <li>了解注释符号、关键字和保留字**-建议手写5遍+记忆5遍**</li> <li>记住标识符的命名规则**-建议手写5遍+记忆5遍**</li> <li>掌握数据类型之整数常量和小数常量**-建议手写5遍+记忆5遍**</li></ul></div></div>  <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B" title="标签">#数据类型</a></div> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/a5bdcf/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">计算机导论与环境配置</div></a> <a href="/pages/0ccc48/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">变量和运算符</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/a5bdcf/" class="prev">计算机导论与环境配置</a></span> <span class="next"><a href="/pages/0ccc48/">变量和运算符</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0c07b2/"><div>
            IT杂货铺
            <!----></div></a> <span class="date">03-23</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/705b35/"><div>
            人事百问
            <!----></div></a> <span class="date">03-22</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/78eb56/"><div>
            MyBatis-Plus
            <!----></div></a> <span class="date">03-12</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:langfeiyes@163.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/langfeiyes" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2024-2024
    <span><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备18007927号-1</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.a2a00aa5.js" defer></script><script src="/assets/js/2.256f807a.js" defer></script><script src="/assets/js/13.0a6ebfcf.js" defer></script>
  </body>
</html>
